import { h } from 'vue';
import { useModalAlert } from '@/hooks';
import { dedup } from '@/utils/utils';

const modalAlert = useModalAlert();

/**
 * @description 门店编码导入校验
 * @author yangwen
 * @param {*} data
 * @return {*}
 */
export const validateStoreCodesImport = (data) => {
  const importList: string[] = data.map((item) => item['门店编码'] || '');
  console.log('afterImport-->data', importList);

  // 数组去重
  const dedupList = dedup(importList);
  // 筛选出超长的门店编码数组（门店编码最大8位）
  const invalidList = dedupList.filter((item) => item.length > 8);
  if (invalidList.length > 0) {
    modalAlert.error('导入错误', h('div', { class: 'overflow-auto' }, `以下门店编码超出8位字符长度限制：${invalidList.join(',')}，请检查正确后再执行导入`));
    return false;
  }

  return true;
};
